{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from trafilatura import fetch_url, extract\n",
    "import pandas as pd\n",
    "from utils import parse_xml, try_parse_json_object, get_text_table, parse_markdwon\n",
    "from tqdm import tqdm\n",
    "import json\n",
    "import re\n",
    "import logging\n",
    "import logging.config\n",
    "import os\n",
    "\n",
    "logger = logging.getLogger(__name__)\n",
    "from zhipuai import ZhipuAI\n",
    "client = ZhipuAI(api_key=\"5e00cf85a0dcf70c5f5573139919c227.elgj3mA5JTNGvoKv\")\n",
    "new_lines = \"=\"*10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt_task = \"\"\"你需要生成的数据如下所示，需要且仅需要这些字段。每个字段的具体指令在对应字段中说明。\n",
    "```json\n",
    "{\n",
    "  \"base_model\": \"{文档中的值是根据什么模型微调的？如果没有明确提到微调，则填入本模型名称}\",\n",
    "  \"base_model_raw_paragraph\": \"{如果找到了 base_model，将依据的段落原文填入此字段，如果没找到，则不填}\",\n",
    "  \"datasets\": \"{使用哪些数据集进行训练？填写数据集的名称，如果没有找到明确的说明，该字段填入“不明”}\",\n",
    "  \"datasets_raw_paragraph\": \"{如果找到了 datasets，将对应的段落原文填入此字段，如果没找到，则不填}\",\n",
    "  \"description\": \"{原封不动地复制原文中的‘模型介绍’相关文段，如果没有找到，则不填}\",\n",
    "}\n",
    "```\n",
    "你非常严谨，只严格提取markdown文件中的信息，如果没有相关信息，则不填，绝不会自己擅自改写。严格按照json格式返回数据，可以让其他程序更方便地处理数据。如果你准备好了，告诉我。\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "prompt_task = \"\"\"你需要生成的数据如下所示，需要且仅需要这些字段。每个字段的具体指令在对应字段中说明。\n",
    "```json\n",
    "{\n",
    "  \"base_model\": \"{文档中的值是根据什么模型微调的？如果没有明确提到微调，则填入本模型名称}\",\n",
    "  \"base_model_raw_paragraph\": \"{如果找到了 base_model，将依据的段落原文填入此字段，如果没找到，则不填}\",\n",
    "  \"datasets\": \"{使用哪些数据集进行训练？填写数据集的名称，如果没有找到明确的说明，该字段填入“不明”}\",\n",
    "  \"datasets_raw_paragraph\": \"{如果找到了 datasets，将对应的段落原文填入此字段，如果没找到，则不填}\",\n",
    "  \"description\": \"{原封不动地复制原文中的‘模型介绍’相关文段，如果没有找到，则不填}\",\n",
    "}\n",
    "```\n",
    "你非常严谨，只严格提取markdown文件中的信息，如果没有相关信息，则不填，绝不会自己擅自改写。严格按照json格式返回数据，可以让其他程序更方便地处理数据。如果你准备好了，告诉我。\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_id = 'meta-llama/Llama-3.1-8B-Instruct'\n",
    "# title_content = parse_markdwon(model_id)\n",
    "title_content, _ = get_text_table(model_id)\n",
    "\n",
    "system_prompt = prompt_task\n",
    "for title, content in title_content.items():\n",
    "    user_prompt = content\n",
    "    response = client.chat.completions.create(\n",
    "        model=\"glm-4-0520\",\n",
    "        messages=[\n",
    "            {\"role\": \"system\", \"content\": system_prompt},\n",
    "            {\"role\": \"user\", \"content\": user_prompt},\n",
    "        ],\n",
    "    )\n",
    "    answer = response.choices[0].message.content\n",
    "    print(answer)\n",
    "\n",
    "    _, answer_dict = try_parse_json_object(answer)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "lccc",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
